package com.study.algorithm.base.list;

import com.study.algorithm.base.common.ListUtil;

import java.util.List;

/**
 * BubbleSort
 *
 * @author wanghuilong
 * @version 1.0
 * @description bubble sort
 * @date 2022/11/6 15:07
 */
public class BubbleSort {

    public static void main(String[] args) {
        List<Integer> list = ListUtil.getRandomList(10);
        System.out.println(list);
        bubbleSort(list);
    }


    public static void bubbleSort(List<Integer> list) {
        for (int i = list.size() - 1; i >= 0; i--) {

            for (int j = 0; j < i; j++) {
                if(list.get(j) > list.get(j+1)) {
                    ListUtil.swap(list,j,j+1);
                }
            }

        }
        System.out.println(list);
    }

}
